import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    activeTab : "all",
    todos : JSON.parse(localStorage.getItem("vuex") || "[]"),
    
  },
  mutations: {
    addTodo : function(state,{payload}){
      state.todos.push({payload});
    },
    bian : function(state){
      state.todos = state.todos.map(v => {
        v.status = state.quan;
      });
    },
  },
  getters : {
    quan : function(state){
      if(todos === state.todos.filter(
        v => {
          if(v.status){
            return true;
          }
        }
      )){
        return true;
      }else{
        return false;
      }
    },
    filterTodos : function(state){
      if(state.activeTab === "all"){
        return state.todos;
      }else if(state.activeTab === "wan"){
        return state.todos.filter(x => {
          if(x.status){
            return true;
          }
        });
      }else if(state.activeTab === "wei"){
        if(!x.status){
          return true;
        }
      };
    },
  },
  actions: {
  },
  modules: {
  }
})
